﻿using System;
using System.Collections.Generic;
using System.Dynamic;
using System.Web.Mvc;
using System.Xml.Linq;
using Xenta.Utils;

namespace Xenta.Web.Controllers
{
    public sealed class RssController : ExtController
    {
        [HttpGet]
        public ActionResult Index()
        {
            dynamic m = new ExpandoObject();
            long rptElapsedTime = 0;
            string rptMimeType = String.Empty;

            m.Error = String.Empty;
            m.Data = null;
            m.ElapsedTime = 0;
            try
            {
                using(var rptData = Svc.BuildReport("ActivityReport",
                    new Dictionary<String, String>
                    {
                        {"languageID", JDM.String(Svc.Localization.Language.EntityID)},
                    },
                    out rptMimeType,
                    out rptElapsedTime))
                {
                    m.Data = XElement.Load(rptData);
                }
            }
            catch(Exception ex)
            {
                m.Error = ex.ToString();
            }
            m.ElapsedTime = rptElapsedTime;

            return View(m);
        }
    }
}
